#pragma once

#include <iostream>
#include <cstdio>
#include <cstdarg>
#include <ctime>
#include <string>

#define DEBUG   0
#define NORMAL  1
#define WARNING 2
#define ERROR   3
#define FATAL   4


 const char* getlog[]={
    "DEBUG",
    "NORMAL",
    "WARNING",
    "ERROR",
    "FATAL"
};

#define LOGFILE "./threadpool.log"

//完整的日志功能，至少: 日志等级 时间 支持用户自定义(日志内容, 文件行，文件名)
void logMessage(int level,const char* type, ...)
{
#ifndef DEBUG_SHOW
    if(level==DEBUG)return;

#endif
    char stdbuffer[1024];
    time_t stdtime=time(nullptr);
    snprintf(stdbuffer,sizeof(stdbuffer),"[%s] [%ld] ", getlog[level],stdtime);

    char custombuffer[1024];
    va_list std;
    va_start(std,type);
    vsnprintf(custombuffer,sizeof(custombuffer),type,std);
    va_end(std);

    //printf("[debug] %s%s\n",stdbuffer,custombuffer);
    FILE*fp=fopen(LOGFILE,"a");//"a" 追加写入
    if(fp>0)
    {
        fprintf(fp,"%s%s\n",stdbuffer,custombuffer);
    }
    fclose(fp);
}

